var fs = require('fs'); 

exports.getData = function(callback){//读文件
    console.log('two')
    fs.readFile('file_views/data.json', function (err, data) {
        if (err) { 
            console.error(err)
            return callback(err);
        }
        console.log(JSON.parse(data));
        var jsonData = JSON.parse(data);
        callback(null,jsonData)
    });
}
exports.uploadData = function(uploadData,callback){//写文件
    console.log('two',uploadData)
    var jsonData = JSON.parse(uploadData)
    var t = JSON.stringify(jsonData);
    console.log('saved',t)
    var date = new Date()
    fs.writeFileSync('file_views/data.json',t);
    fs.writeFileSync('./dataHistory.txt',t+' '+date.toLocaleString()+'\n',{flag:"a"});
    callback(null,'success')
}